import 'dart:developer';
import 'package:transparent_pointer/transparent_pointer.dart';

import 'equal_model.dart';
import 'staless.dart';
import 'package:flutter/material.dart';

class ColumnPage extends StatefulWidget {
  const ColumnPage({Key? key}) : super(key: key);

  @override
  State<ColumnPage> createState() => _ColumnPageState();
}

class _ColumnPageState extends State<ColumnPage> with WidgetsBindingObserver {
  final FocusNode _focusNode = FocusNode();

  @override
  void initState() {
    super.initState();
    _focusNode.addListener(() {
      if (_focusNode.hasFocus) {
        print('获取焦点');
      } else {
        print('失去焦点');
      }
    });
    // 注册监听
    WidgetsBinding.instance.addObserver(this);
    print('---');
    Map<String, dynamic> map = {
      'name': '王帅宇',
    };
    String? s = map['age']?['color']?['s'];
    print('S 是 $s');
    String age = map['age'] as String? ?? "";
    print('字符串是$age');

    final List<String> listStr = ['1', '2', '3'];
    listStr.removeWhere((element) => element == '1');
    log('listStr $listStr');
    const a = (-6) ~/ 4;
    const b = 8 ~/ 10;
    const c = 12 % 3;
    const d = 12 / 3;
    const e = 11 % 3;
    log('a = $a');
    log('商 = $b');
    log('余数 = $c');
    log('--除$d --模或者商$e');

    EqualModel model1 = EqualModel(1, 'first');
    EqualModel model2 = EqualModel(1, 'first');
    List<EqualModel> list1 = [const EqualModel(1, 'first'), const EqualModel(2, 'second')];
    List<EqualModel> list2 = [const EqualModel(1, 'first'), const EqualModel(2, 'second')];
    Set set1 = list1.toSet();
    print('-----------');
    print(list1 == list2);
    print(model1 == model2);

    int? value;
    String? valueStr = value?.toString();
    String? str1 = '';
    print('==&&== ${int.tryParse(str1)} -- ${value?.toString()}');
  }

  @override
  Widget build(BuildContext context) {
    const String first = 'http://idnaaidnaaidnaaidnaaidnaaidnaaidnaaidnaaidnaaidnaaidnaaidnaaidnaaidnaa';
    const String second = 'http://niaaidaaidaaid';
    return WillPopScope(
      onWillPop: () async {
        print('准备退出了');
        Navigator.of(context).pop();
        return false;
      },
      child: Scaffold(
          resizeToAvoidBottomInset: false,
          appBar: AppBar(),
          body: Center(
            child: TextField(focusNode: _focusNode),
          )),
    );
  }

  // 页面大小规模发生变化的回调方法
  @override
  void didChangeMetrics() {
    super.didChangeMetrics();
    // 在页面重新渲染完成之后再去获取 `MediaQuery.of(context).viewInsets.bottom`
    WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
      final value = MediaQuery
          .of(context)
          .viewInsets
          .bottom;
      if (value > 0) {
        print("键盘弹起：$value");
      }
    });
  }

  @override
  void dispose() {
    // 移除监听
    WidgetsBinding.instance.removeObserver(this);
    super.dispose();
  }
}
